package com.tdd;

import java.util.concurrent.ConcurrentHashMap;

public class OperationFactory {
	ConcurrentHashMap<String, Operation> operators = new ConcurrentHashMap<String, Operation>();

	public OperationFactory() {
		operators.put("+", new Plus());
		operators.put("-", new Minus());
		operators.put("*", new Multiply());
		operators.put("/", new Divide());
		operators.put("!", new Factorial());
	}

	public Operation findOperationNamed(String operatorName) {
		Operation op = operators.get(operatorName);

		if (op == null)
			throw new RuntimeException(String.format("%s - unknown operator",
					operatorName));

		return op;
	}
}
